
#!/bin/bash

CURRENT_DIRECTORY=`pwd`
SCRIPTS_DIR=${CURRENT_DIRECTORY}/out/scripts
SCRIPTS_BUILD_DIR=${SCRIPTS_DIR}/build
EMBED_RESOURCE_IN=${CURRENT_DIRECTORY}/src/scripts
EMBED_RESOURCE_OUT=${SCRIPTS_DIR}/out

rm -fr ${SCRIPTS__BUILD_DIR}

source `dirname $0`/build_embed_resource.sh

${EMBED_RESOURCE} --in_directory ${EMBED_RESOURCE_IN} --out_directory ${EMBED_RESOURCE_OUT}
cp ${EMBED_RESOURCE_DIR}/Resource.h ${EMBED_RESOURCE_OUT}

cat > ${EMBED_RESOURCE_OUT}/CMakeLists.txt <<EOF
cmake_minimum_required (VERSION 3.20.0)
project(luagui-scripts)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)

aux_source_directory(\${CMAKE_CURRENT_SOURCE_DIR} DIR_SRCS)
add_library(\${PROJECT_NAME} \${DIR_SRCS})
EOF

cmake -S ${EMBED_RESOURCE_OUT} -B ${SCRIPTS_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release
cmake --build ${SCRIPTS_BUILD_DIR}

#mkdir -p ${CURRENT_DIRECTORY}/libs/resources
#cp ${EMBED_RESOURCE_DIR}/out/scripts/out/libluagui-scripts.a ${CURRENT_DIRECTORY}/libs/resources
